﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AO.Core;
using Cell.Core;

namespace LoginEngine
{
    public static class OnlineChars
    {
        /// <summary>
        /// Sets all account to offline status.
        /// </summary>
        public static void Initialize()
        {

        }

        public static bool IsOnline(int ID)
        {
            MySqlWrapper sql = new MySqlWrapper();
            sql.MySqlRead("SELECT * FROM characters WHERE ID = " + ID + ";");

            if (sql.myreader.Read() == false)
            {
                throw new Exception("Character does not exist");
            }

            if (sql.myreader.GetInt16("Online") == 1)
            {
                sql.mcc.Close();
                sql.myreader.Close();
                return true;
            }
            else
            {
                sql.mcc.Close();
                sql.myreader.Close();
                return false;
            }
        }

        public static void SetOnline(int ID)
        {
            MySqlWrapper sql = new MySqlWrapper();
            sql.MySqlUpdate("UPDATE characters SET Online = 1 WHERE ID = " + ID + ";");
            sql.mcc.Close();
            //sql.myreader.Close();
        }
    }
}
